﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RBOSS.Business.Checkout;
using RBOSS.Business.Presenters;
using RBOSS.Business.Views;
using RBOSS.WebUI.Models;

namespace RBOSS.WebUI
{
    public partial class CheckoutForm : MasterSite, IShoppingCartView
    {
        private readonly ShoppingCartPresenter _shoppingCartPresenter;
        public IShipping Shipping { get; set; }
        public IBilling Billing{ get; set; }
        private ICheckoutSubsystem _checkoutSubsystem; 
        public CheckoutForm()
        {
            _shoppingCartPresenter = new ShoppingCartPresenter(this);
            _checkoutSubsystem = new CheckoutSubsystem();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            UpdateProductList();
            Billing = _checkoutSubsystem.GetBillingInfo();
            Shipping= _checkoutSubsystem.GetShippingInfo();
            WireupEven();
        }

        private void UpdateProductList()
        {
            var products = _shoppingCartPresenter.GetProducts();
            gvProduct.DataSource = products;
            gvProduct.DataBind();

            ShowCheckoutButton(false);

        }

        private void WireupEven()
        {
            butConfirmPayment.Click += ConfirmPaymentClick;
        }

        private void ConfirmPaymentClick(object sender, EventArgs e)
        {
            _checkoutSubsystem.Checkout();
            Response.Redirect("ThankYou.aspx");
        }
    }
}
